package com.zzyy.study.service;

import cn.hutool.core.util.IdUtil;
import com.zzyy.study.annotation.ServiceSwitch;
import com.zzyy.study.constant.Constant;
import com.zzyy.study.resp.ResultData;
import jakarta.annotation.Resource;
import lombok.extern.slf4j.Slf4j;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.http.HttpStatus;
import org.springframework.stereotype.Service;

import java.util.UUID;
import java.util.concurrent.ThreadLocalRandom;

/**
 * @auther zzyy
 * @create 2024-01-13 18:04
 */

@Service
@Slf4j
public class OrderService
{
    public static final String ORDER_KEY = "order:";

    @Resource
    private RedisTemplate redisTemplate;

    public void addOrder()
    {
        int keyId = ThreadLocalRandom.current().nextInt(1000)+1;
        String orderNo = IdUtil.simpleUUID();
        redisTemplate.opsForValue().set(ORDER_KEY+keyId,"京东订单"+ orderNo);
        log.info("=====>编号"+keyId+"的订单流水生成:{}",orderNo);
    }

    public String getOrderById(Integer id)
    {
        return (String)redisTemplate.opsForValue().get(ORDER_KEY + id);
    }


    /**
     * 下单
     */
    @ServiceSwitch(switchKey = Constant.ConfigCode.WX_PAY_SWITCH)
    public ResultData addOrderSwitch() {

        // 具体下单业务逻辑省略....

        return ResultData.success("服务微信支付下单成功");
    }
}

